﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverRaport
{
    public partial class MainPage : UserControl
    {
        MySilverRaporService.SilverRaporServiceClient MyService = new MySilverRaporService.SilverRaporServiceClient();
        public bool Giris;
        public MainPage()
        {
            InitializeComponent();
            btnGiris.Click += new RoutedEventHandler(btnGiris_Click);
            txtPass.KeyDown += new KeyEventHandler(txtPass_KeyDown);
            txtUser.GotFocus += (e, a) =>
            {
                txtUser.Text = "";
            };
        }
        private void KullaniciGiris()
        {
            MyService.KullaniciBulAsync(txtUser.Text, txtPass.Password);
            MyService.KullaniciBulCompleted += new EventHandler<MySilverRaporService.KullaniciBulCompletedEventArgs>(MyService_KullaniciBulCompleted);
        }
        void txtPass_KeyDown(object sender, KeyEventArgs e)
        {
            if (Key.Enter == e.Key)
            {
                KullaniciGiris();
            }
        }

        void MyService_KullaniciBulCompleted(object sender, MySilverRaporService.KullaniciBulCompletedEventArgs e)
        {
            try
            {
                if (e.Result.GetType() == typeof(int))
                {
                    load.Close();
                    this.LayoutRoot.Children.Clear();
                    SqlPage.KullaniciID = (int)e.Result;
                    this.LayoutRoot.Children.Add(new SqlPage());

                }
                else
                    MessageBox.Show("Kullanıcı Kayıtlı Değil..!!");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hata  : " + ex.Message +"\n inner Exception : "+ex.InnerException, "Hata..!!", MessageBoxButton.OK);
            }
        }
        Loading load = new Loading();
        void btnGiris_Click(object sender, RoutedEventArgs e)
        {
            KullaniciGiris();
            load.Show();
        }


    }
}
